﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RateCounterAPI;

namespace NRatingCounter {
    /// <summary>
    /// 集計実行画面
    /// </summary>
    public partial class ExecuteDialog : Form {
        private AvgCounter _avg;

        public ExecuteDialog(AvgCounter avg) {
            InitializeComponent();
            _avg = avg;
            _avg.ProgressChanged += new EventHandler(_avg_ProgressChanged);
            _avg.CountCompleted += new EventHandler(_avg_CountCompleted);
        }

        private void ExecuteDialog_Load(object sender, EventArgs e) {
            _avg.Start();
        }

        void _avg_ProgressChanged(object sender, EventArgs e) {
            double score = Math.Round(_avg.Score, 1, MidpointRounding.AwayFromZero);
            txtScore.Text = score.ToString("0.00");
        }

        void _avg_CountCompleted(object sender, EventArgs e) {
            btnClose.Visible = true;
            btnStop.Visible = false;
        }

        private void btnStop_Click(object sender, EventArgs e) {
            _avg.Stop();
        }

        private void btnClose_Click(object sender, EventArgs e) {
            Close();
        }
    }
}
